package cn.liujianbo.example.validate.result;

import lombok.Data;

import java.io.Serializable;
import java.util.Collections;

/**
 * @author 刘建波
 * @date 2020-12-24 14:00
 */
@Data
public class R<T> implements Serializable{

    private static final long SERIALIZABLE_ID = 1L;

    /**
     * 成功标志
     */
    private boolean success;

    /**
     * 消息
     */
    private String message;

    /**
     * 返回代码
     */
    private Integer code;

    /**
     * 时间戳
     */
    private long timestamp = System.currentTimeMillis();

    /**
     * 结果对象
     */
    private T result;

    public static R<Object> ok(){
        R<Object> r = new R<>();
        r.success = true;
        r.code = 200;
        r.message = "查询成功";
        r.result = Collections.emptyList();
        return r;
    }

    public static R<Object> error(String msg){
        R<Object> r = new R<>();
        r.success = true;
        r.code = 400;
        r.message = msg;
        return r;
    }

    public static R<Object> ok(Object t){
        R<Object> r = new R<>();
        r.success = true;
        r.code = 200;
        r.message = "查询成功";
        r.result = t;
        return r;
    }
}
